/**
 *
 */
package com.yuxi.common.format;

import org.springframework.beans.propertyeditors.PropertiesEditor;

public class IntegerEditor extends PropertiesEditor {
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if (text == null || ("").equalsIgnoreCase(text) || "null".equalsIgnoreCase(text)) {
            text = null;
        }
        if (text != null) {
            setValue(Integer.parseInt(text));
        } else {
            setValue(null);
        }
    }

    @Override
    public String getAsText() {
        if (getValue() == null) {
            return null;
        }
        return getValue().toString();
    }
}
